<div class="sm-rightPanel bg-darken">
    <div class="layui-anim layui-anim-upbit">
        <blockquote class="site-text layui-elem-quote">
            关键字回复
        </blockquote>
        <div class="layui-form-item" id="list_form">
            <div class="layui-inline">
                <a class="layui-btn layui-btn-danger" href="javascript:;" id="batch_del">批量删除</a>
                <a class="layui-btn layui-btn-normal" href="/views/index.html#/wx/reply/keywords/keywords-add">添加</a>
            </div>
        </div>
        <table id="list_table" class="layui-hide" lay-filter="mainList"></table>
    </div>
</div>
<script>
    layui.use(['layer', 'table'], function () {
        var layer = layui.layer;
        var table = layui.table;

        var tableObj = table.render({
            id: 'list_table',
            elem: '#list_table',
            url: '/wxcms/replykey/list',
            align: "center",
            cols: [[
                {type: 'checkbox'},
                {type: 'numbers', title: '序号', width: 50},
                {field: 'name', title: '规则名', width: 150, align: 'center',},
                {field: 'msgType', title: '回复类型', width: 150, align: 'center',templet: function (d) {
                	console.log(JSON.stringify(d));
                   switch (d.msgType){
                        case "text": 
                        	return "文本";
                        case "voice": 
                        	return "语音";
                        case "video": 
                        	return "视频";
                        case "image": 
                        	return "图片";
                        default:
                        	return "图文";
                    }
                }},
//                 {field: 'userId', title: '用户', width: 150, align: 'center',},
                {field: 'createTime', title: '创建时间', width: 200, align: 'center',},
                {field: 'updateTime', title: '编辑时间', width: 200, align: 'center',},
                {
                    field: 'lock', title: '操作', width: 250, align: 'center', templet: function (d) {
                    return '<a class="font-primary" href="/views/index.html#/wx/reply/keywords/keywords-add[id='+d.id+']">查看/编辑</a>'
                    +'<a class="font-danger" lay-event="del" href="javascript:;">删除</a>';
                }, unresize: true
                }
            ]],
        });

        //表格内部操作按钮监听
        table.on('tool(mainList)', function (obj) {
//         	var data = table.checkStatus('list_table').data;//已选中数据
//             if (data.length == 0) {
//                 layer.msg("至少选择一条");
//                 return;
//             }
            var arr = [];     //选中数组
//             for (var i = 0; i < data.length; i++) {
//                 arr.push(data[i].id)
//             }
            var data = obj.data;
            arr.push(data.id);
            var layEvent = obj.event;

            if (layEvent === 'del') {
                smartAui.confirm("确认删除？", function () {
                    smartAui.ajax({
                        loading:true,
//                         url: '/wxcms/replykey/deleteBatch',
                        url: '/wxcms/replykey/delete',
//                         data: {"ids": arr},
                        data: {id: data.id},
                        success: function (result) {
                            if (result.success) {
                                layer.msg("操作成功");
                                smartAui.reloadTable(tableObj);
                            } else {
                                layer.msg("操作异常");
                            }
                        }
                    })
                });
            }
        });
        //批量删除
        $("#batch_del").click(function(){
        	
        	var data = table.checkStatus('list_table').data;//已选中数据
	         if (data.length == 0) {
	             layer.msg("至少选择一条");
	             return;
	         }
	         var arr = [];     //选中数组
	         for (var i = 0; i < data.length; i++) {
	             arr.push(data[i].id)
	         }
	         smartAui.confirm("确认删除？", function () {
                 smartAui.ajax({
                     loading:true,
                     url: '/wxcms/replykey/deleteBatch',
                     data: {"ids": arr},
                     success: function (result) {
                         if (result.success) {
                             layer.msg("操作成功");
                             smartAui.reloadTable(tableObj);
                         } else {
                             layer.msg("操作异常");
                         }
                     }
                 })
             });
        });
    });
</script>
